home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_11_01
/
1101068a
< prev
next >
Wrap
Text File
|
1992-11-01
|
787b
|
43 lines
int
igchecksum (z, c)
register const char *z;
register int c;
{
register unsigned int ichk1, ichk2;
ichk1 = 0xffff;
ichk2 = 0;
do
{
register unsigned int b;
/* Rotate ichk1 left. */
if ((ichk1 & 0x8000) == 0)
ichk1 <<= 1;
else
{
ichk1 <<= 1;
++ichk1;
}
/* Add the next character to ichk1. */
b = *z++ & 0xff;
ichk1 += b;
/* Add ichk1 xor the character position in the buffer counting from
the back to ichk2. */
ichk2 += ichk1 ^ c;
/* If the character was zero, or adding it to ichk1 caused an
overflow, xor ichk2 to ichk1. */
if (b == 0 || (ichk1 & 0xffff) < b)
ichk1 ^= ichk2;
}
while (--c > 0);
return ichk1 & 0xffff;
}